package org.dromara.system.controller.autocode;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import org.dromara.autocode.service.SysAutoCodePartService;
import org.dromara.autocode.strategy.AutoCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SaIgnore
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/autocode")
public class SysAutoCodeController {

    @Autowired
    private AutoCodeUtil autoCodeUtil;

  @Autowired
  private SysAutoCodePartService iAutoCodePartService;


    @GetMapping(value = {"/get/{ruleCode}/{inputCharacter}","/get/{ruleCode}"})
    public String getAutoCode(@PathVariable String ruleCode,@PathVariable(required = false) String inputCharacter){
        return autoCodeUtil.genSerialCode(ruleCode,inputCharacter);
    }
/*

  @SaCheckPermission("@ss.hasPermi('system:autocode:part:list')")
  @GetMapping("/list")
  public TableDataInfo list(SysAutoCodePart sysAutoCodePart){
    startPage();
    List<SysAutoCodePart> parts = iAutoCodePartService.listPart(sysAutoCodePart);
    return getDataTable(parts);
  }

  @SaCheckPermission("@ss.hasPermi('system:autocode:part:query')")
  @GetMapping("/{partId}")
  public AjaxResult getInfo(@PathVariable Long partId){
    return AjaxResult.success(iAutoCodePartService.findById(partId));
  }


  @SaCheckPermission("@ss.hasPermi('system:autocode:part:insert')")
  @Log(title = "新增编码生产规则组成部分",businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody SysAutoCodePart part){
    if(UserConstants.NOT_UNIQUE.equals(iAutoCodePartService.checkPartUnique(part))){
      return AjaxResult.error("规则组成不唯一，清检查组成编码、组成名称、组成序号");
    }
    part.setCreateBy(getUsername());
    return toAjax(iAutoCodePartService.insertPart(part));
  }

  @SaCheckPermission("@ss.hasPermi('system:autocode:part:update')")
  @Log(title = "更新物料编码",businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult update(@Validated @RequestBody SysAutoCodePart sysAutoCodePart){
    if(UserConstants.NOT_UNIQUE.equals(iAutoCodePartService.checkPartUnique(sysAutoCodePart))){
      return AjaxResult.error("规则组成不唯一，清检查组成编码、组成名称、组成序号");
    }
    sysAutoCodePart.setUpdateBy(getUsername());
    return toAjax(iAutoCodePartService.updatePart(sysAutoCodePart));
  }


  @SaCheckPermission("@ss.hasPermi('system:autocode:part:remove')")
  @Log(title = "删除物料编码",businessType = BusinessType.DELETE)
  @DeleteMapping("/{partIds}")
  public AjaxResult delete(@PathVariable Long[] partIds){
    return toAjax(iAutoCodePartService.deleteByIds(partIds));
  }
*/


}
